require("prefabutil")

local assets =
{
    Asset("ANIM", "anim/bboy_lucky_cat.zip"),
}

local prefabs =
{
    "collapse_small",
}

local function onworkfinished(inst)
    inst.components.lootdropper:DropLoot()
    local fx = SpawnPrefab("collapse_small")
    fx.Transform:SetPosition(inst.Transform:GetWorldPosition())
    inst:Remove()
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddNetwork()

    inst:SetDeploySmartRadius(0.5)
    MakeObstaclePhysics(inst, .4)

    inst.MiniMapEntity:SetIcon("bboy_lucky_cat.png")

    inst.AnimState:SetBank("bboy_lucky_cat")
    inst.AnimState:SetBuild("bboy_lucky_cat")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("structure")

    -- MakeSnowCoveredPristine(inst)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    MakeHauntableWork(inst)
    -- MakeSnowCovered(inst)

    inst:AddComponent("workable")
    inst.components.workable:SetWorkAction(ACTIONS.HAMMER)
    inst.components.workable:SetWorkLeft(4)
    inst.components.workable:SetOnFinishCallback(onworkfinished)

    inst:AddComponent("bboy_worship")

    inst:AddComponent("timer")

    inst:ListenForEvent("timerdone", function(inst, data)
        if data ~= nil then
            inst.components.bboy_worship:OnTimerDone(data.name)
        end
    end)

    inst:AddComponent("inspectable")

    inst:AddComponent("lootdropper")

    return inst
end

return Prefab("bboy_lucky_cat", fn, assets, prefabs),
    MakePlacer("bboy_lucky_cat_placer", "bboy_lucky_cat", "bboy_lucky_cat", "idle")
